using UnityEngine;
using System.Collections;

public class TransitionOnDirectionEvent : CharacterAction
{
	public enum DirectionEventType
	{
		OnDirection,
		OnDirectionEnd
	}
	public DirectionEventType eventType;
	public CharacterAnimatedState toState;
 
	public override void OnActionEnter (Character character)
	{
		if(eventType == DirectionEventType.OnDirection)
			character.onDirectionCommand.OnEvent += OnDirectionCommand;
		if(eventType == DirectionEventType.OnDirectionEnd)
			character.onDirectionCommandEnd.OnEvent += OnDirectionCommandEnd;
	}
	
	public override void OnActionExit (Character character)
	{
		if(eventType == DirectionEventType.OnDirection)
			character.onDirectionCommand.OnEvent -= OnDirectionCommand;
		if(eventType == DirectionEventType.OnDirectionEnd)
			character.onDirectionCommandEnd.OnEvent -= OnDirectionCommandEnd;
	}

	public void OnDirectionCommand (Character.DirectionCommand arg)
	{
		if(string.IsNullOrEmpty(arg.newStateName)){
			arg.character.ToState(toState.stateName);
		}
		else{
			arg.character.ToState(arg.newStateName);
		}
	}

	public void OnDirectionCommandEnd (Character.DirectionCommandEnd arg)
	{
		if(string.IsNullOrEmpty(arg.newStateName)){
			arg.character.ToState(toState.stateName);
		}
		else{
			arg.character.ToState(arg.newStateName);
		}
	}
}

